/**
 * 业务管理管理初始化
 */
var CustomerCompanyManage = {
    id: "CustomerCompanyManageTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
CustomerCompanyManage.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '客户名称', field: 'customerCompanyName', visible: true, align: 'center', valign: 'middle'},
        {title: '客户类型', field: 'customerTypeCode', visible: true, align: 'center', valign: 'middle'},
        {title: '年销售收入规模（万元）', field: 'annualIncome', visible: true, align: 'center', valign: 'middle'},
        {title: '客户数量', field: 'customerNum', visible: true, align: 'center', valign: 'middle'},
        {title: '年度采购规模', field: 'annualPurchaseAmount', visible: true, align: 'center', valign: 'middle'},
        {title: '供应商数量', field: 'providerNum', visible: true, align: 'center', valign: 'middle'},
        {title: '所属部门', field: 'deptName', visible: true, align: 'center', valign: 'middle'},
        {title: '所属销售', field: 'salesmanName', visible: true, align: 'center', valign: 'middle'},
        {title: '信息来源', field: 'source', visible: true, align: 'center', valign: 'middle'},
        {title: '是否建行账户', field: 'isCcbV', visible: true, align: 'center', valign: 'middle'},
        {title: '是否计划开户', field: 'isPlanToOpenAccountV', visible: true, align: 'center', valign: 'middle'},
        {title: '当前状态', field: 'state', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
CustomerCompanyManage.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        CustomerCompanyManage.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加业务管理
 */
CustomerCompanyManage.openAddCustomerCompanyManage = function () {
    var index = layer.open({
        type: 2,
        title: '添加业务管理',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customerCompanyManage/customerCompanyManage_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看业务管理详情
 */
CustomerCompanyManage.openCustomerCompanyManageDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '业务管理详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/customerCompanyManage/customerCompanyManage_update/' + CustomerCompanyManage.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除业务管理
 */
CustomerCompanyManage.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/customerCompanyManage/delete", function (data) {
            Feng.success("删除成功!");
            CustomerCompanyManage.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("customerCompanyId", this.seItem.customerCompanyId);
        ajax.start();
    }
};

CustomerCompanyManage.resetSearch = function(){
    $("#customerTypeCode").val("");
    $("#customerCompanyName").val("");
    CustomerCompanyManage.search();
}
/**
 * 查询业务管理列表
 */
CustomerCompanyManage.search = function () {
    var queryData = {};
    queryData['customerTypeCode'] = $("#customerTypeCode").val();
    queryData['customerCompanyName'] = $("#customerCompanyName").val();
    CustomerCompanyManage.table.refresh({query: queryData});
};

/**
 * 显示部门选择的树
 */
CustomerCompanyManage.showDeptSelectTree = function () {
    Feng.showInputTree("departName", "deptTypeTreeDiv", 15, 34);
};

/**
 * 选择部门
 * @param e
 * @param treeId
 * @param treeNode
 */
CustomerCompanyManage.onClickDept = function (e, treeId, treeNode) {
    $("#departName").attr("value", treeNode.name);
    $("#departId").attr("value", treeNode.id);
}


$(function () {
    var defaultColunms = CustomerCompanyManage.initColumn();
    var table = new BSTable(CustomerCompanyManage.id, "/customerCompanyManage/list", defaultColunms);
    table.setPaginationType("server");
    CustomerCompanyManage.table = table.init();
});
